import {FormConfig} from "vj-tool/vj-tool/types";
import {genFormOptions} from "vijay-util";
import {CITY_DATA} from "@/config/properties";
const optionsFn = (names) => ({options:names.map((name) => ({label: name, value: name}))});

export const GameFM: FormConfig = [
    {label: "游戏名称", name: "name", type: "vjInput"},
    {label: "游戏封面", name: "coverUrl", type: "vjUpload"},
    {label: "游戏版本", name: "version", type: "vjInput"},
    {label: "游戏地址", name: "url", type: "vjInput"},
    {label: "后台地址", name: "backgroundUrl", type: "vjInput"},
    {label: "后台账号", name: "backgroundUsername", type: "vjInput"},
    {label: "后台密码", name: "backgroundPassword", type: "vjInput"},
    {label: "备注", name: "remark", type: "vjInput", config: {type: "textarea", rows: 3}},
];
export const AboutFM: FormConfig = [
    {label: "联系我们", name: "details", type: "vjInput", cmp: "rich"},
];
export const RuleFM: FormConfig = [
    {label: "参赛资格", name: "details", type: "vjInput", cmp: "rich"},
];
export const CustomModuleFM: FormConfig = [
    {label: "图片", name: "img", type: "vjUpload"},
    {label: "链接", name: "url", type: "vjInput"},
    {label: "主题", name: "sub", type: "vjInput"},
    {label: "名称", name: "name", type: "vjInput"},
    {label: "状态", name: "status", type: "vjSelect", config: genFormOptions(["上架", "下架"], 1)},
];
export const PropagandaFM: FormConfig = [
    {label: "图片", name: "coverUrl", type: "vjUpload"},
    {label: "链接", name: "name", type: "vjInput"},
    {label: "状态", name: "name", type: "vjSelect", config: genFormOptions(["创业大赛", "创业活动"])},
];
export const ACTIVITY_FM: FormConfig = [
    {label: "活动标题", name: "title", type: "vjInput"},
    {label: "活动类型", name: "type", type: "vjSelect", config: genFormOptions(["创业大赛", "创业活动"], 1)},
    {
        label: "活动时间",
        name: "actstarttime",
        names: ["actstarttime", "actendtime"],
        type: "vjDate",
        config: {type: "daterange"}
    },
    {
        label: "报名时间",
        name: "signstarttime",
        names: ["signstarttime", "signendtime"],
        type: "vjDate",
        config: {type: "daterange"}
    },
    {
        label: "省市区",
        name: "actprovince",
        names: ["actprovince", "actcity", "actarea"],
        type: "vjAddr",
        config: {options: CITY_DATA}
    },
    {label: "详细地址", name: "actaddress", type: "vjInput"},
    {label: "主办方", name: "sponsor", type: "vjInput"},
    {label: "活动海报", name: "actbill", type: "vjUpload"},
    {label: "正文", name: "actdetails", type: "vjInput", cmp: "rich"},
    {label: "是否需要审核", name: "isaud", type: "vjSelect", cmp: "radio", config: genFormOptions(["审核", "不审核"], 1)},
    {
        label: "人数限制",
        name: "islimit",
        names: ["islimit", "limitpeople"],
        type: "vjRadioCmp",
        config: genFormOptions(["不限制", "限制"], 1, 1)
    },
    {label: "已报用户", name: "issign", type: "vjSelect", cmp: "radio", config: genFormOptions(["不显示", "显示"], 1)},
];
export const ACTIVITY_LINK_FM: FormConfig = [
    {label: "活动标题", name: "title", type: "vjInput"},
    {label: "活动类型", name: "type", type: "vjSelect", config: genFormOptions(["创业大赛", "创业活动"], 1)},
    {
        label: "活动时间",
        name: "actstarttime",
        names: ["actstarttime", "actendtime"],
        type: "vjDate",
        config: {type: "daterange"}
    },
    {
        label: "报名时间",
        name: "signstarttime",
        names: ["signstarttime", "signendtime"],
        type: "vjDate",
        config: {type: "daterange"}
    },
    {
        label: "省市区",
        name: "actprovince",
        names: ["actprovince", "actcity", "actarea"],
        type: "vjAddr",
        config: {options: CITY_DATA}
    },
    {label: "详细地址", name: "actaddress", type: "vjInput"},
    {label: "主办方", name: "sponsor", type: "vjInput"},
    {label: "活动海报", name: "actbill", type: "vjUpload"},
    {label: "正文", name: "actdetails", type: "vjInput", cmp: "rich"},
];
export const JOB_FM: FormConfig = [
    {label: "岗位名称", name: "name", type: "vjInput"},
    {label: "状态", name: "status", type: "vjSelect", config: genFormOptions(["上架", "下架"])},
];
export const PIC_FM: FormConfig = [
    {label: "图片名称", name: "imgname", type: "vjInput"},
    {label: "图片分类", name: "type", type: "vjSelect", config: genFormOptions([])},
    {label: "选择图片", name: "url", type: "vjUpload"},
];
export const COMPANY_FAIR_FM: FormConfig = [
    {label: "招聘会名称", name: "imgname", type: "vjInput"},
    {label: "选择图片", name: "picture", type: "vjUpload"},
    {label: "链接", name: "url", type: "vjInput"},
];
export type FormFunc = (...args) => FormConfig;
export function dynamicForm(arr: FormConfig): FormConfig {
    return arr.reduce((acc, cur) => {
        const notAllow = Array.isArray(cur) && cur[1] !== cur[2];
        Array.isArray(cur) && (cur = cur[0]);
        return notAllow ? acc : acc.concat(cur as any)
    }, [])
}
export const COMPANY_FM: FormFunc = (type) => dynamicForm([
    {label: "企业全称", name: "name", type: "vjInput"},
    {label: "企业简称", name: "abbreviate", type: "vjInput"},
    {label: "所属行业", name: "trade", type: "vjInput"},
    ...addressCfgFn('address'),
    {label: "企业LOGO", name: "picture", type: "vjUpload"},
    {label: "企业营业执照", name: "license", type: "vjUpload"},
    {label: "企业荣誉", name: "honour", type: "vjInput"},
    {label: "企业简介", name: "remarks1", type: "vjInput", config: {type: "textarea", rows: 5}},
    {label: "注册手机号", name: "phone", type: "vjInput"},
    {label: "联系人", name: "contact", type: "vjInput"},
    {label: "提交时间", name: "createTime", type: "vjInput"},
    [{
        label: "审核结果",
        name: "status",
        type: "vjSelect",
        cmp: "radio",
        config: genFormOptions(["通过", "不通过"], 2)
    }, type, 1],
    [{label: "审核意见", name: "remarks2", type: "vjInput"}, type, 1],
]);
export const COMPANY_ADD_FM: FormFunc = (type) => dynamicForm([
    {label: "企业全称", name: "name", type: "vjInput"},
    {label: "企业简称", name: "abbreviate", type: "vjInput"},
    {label: "所属行业", name: "trade", type: "vjSelect", config: optionsFn(["信息传输、计算机服务和软件业", "教育", "建筑业", "制造业"])},
    ...addressCfgFn('address'),
    {label: "企业LOGO", name: "picture", type: "vjUpload"},
    {label: "企业营业执照", name: "license", type: "vjUpload"},
    {label: "企业荣誉", name: "honour", type: "vjSelect", config: optionsFn(["AAA信用评级证书", "中国百强诚信企业", "中国低碳产品"])},
    {label: "企业简介", name: "remarks1", type: "vjInput", config: {type: "textarea", rows: 5}},
    {label: "注册手机号", name: "phone", type: "vjInput"},
    {label: "联系人", name: "contact", type: "vjInput"},
]);
export const COMPANY_JOB_FM: FormConfig = [
    {label: "岗位名称", name: "name", type: "vjInput"},
    {label: "岗位名称", name: "name", type: "vjInput"},
    {label: "工作地点", name: "abbreviate", type: "vjInput"},
    {label: "招聘人数", name: "peoplenum", type: "vjNumber"},
    // {label: "薪资待遇", name: "q", names: ["q","p"], type: "vjNumber", cmp: "range"},
    // {label: "薪资类型", name: "e", type: "vjSelect", config: genFormOptions(["月", "年"])},
    // {label: "工作年限", name: "w", names: ["w","x"], type: "vjNumber", cmp: "range"},
    {label: "招聘要求", name: "remarks1", type: "vjInput", config: {type: "textarea", rows: 3}},
    {label: "公司介绍", name: "remarks2", type: "vjInput", config: {type: "textarea", rows: 3}},
];
export const PWD_FM: FormConfig = [
    {label: "原始密码", name: "imgname", type: "vjInput"},
    {label: "新密码", name: "imgname", type: "vjInput"},
    {label: "确认密码", name: "imgname", type: "vjInput"},
];
export const REGISTER_FM: FormConfig = [
    {label: "企业全称", name: "name", type: "vjInput"},
    {label: "企业简称", name: "abbreviate", type: "vjInput"},
    {label: "所属行业", name: "trade", type: "vjSelect", config: optionsFn(["信息传输、计算机服务和软件业", "教育", "建筑业", "制造业"])},
    ...addressCfgFn('address'),
    {label: "企业LOGO", name: "picture", type: "vjUpload"},
    {label: "企业营业执照", name: "license", type: "vjUpload"},
    {label: "企业荣誉", name: "honour", type: "vjSelect", config: optionsFn(["AAA信用评级证书", "中国百强诚信企业", "中国低碳产品"])},
    {label: "企业简介", name: "remarks1", type: "vjInput", config: {type: "textarea", rows: 5}},
    {label: "注册手机号", name: "phone", type: "vjInput"},
    {label: "联系人", name: "contact", type: "vjInput"},
];
export const TALENT_FM: FormConfig = [
    {label: "公司名称", name: "name", type: "vjInput"},
    ...addressCfgFn(),
    {label: "公司logo上传", name: "picture", type: "vjUpload"},
    {label: "岗位名称", name: "postsname", type: "vjInput"},
    {label: "薪资范围", name: "minsalary", names: ["minsalary", "maxsalary"], type: "vjNumber", cmp: "range"},
    {label: "学历要求", name: "education", type: "vjInput"},
    {label: "融资程度", name: "degree", type: "vjInput"},
    {label: "岗位分类", name: "typeid", type: "vjSelect", config: genFormOptions([])},
    {label: "公司人数范围", name: "mincompanies", names: ["mincompanies", "maxcompanies"], type: "vjNumber", cmp: "range"},
    {label: "标签", name: "tag", type: "vjInput"},
    {label: "详情", name: "details", type: "vjInput", cmp: "rich"},
];
export const POLICY_FM: FormConfig = [
    {label: "封面图片", name: "picture", type: "vjUpload"},
    {label: "标题", name: "title", type: "vjInput"},
    {label: "发布者", name: "createuser", type: "vjInput"},
    {
        label: "政治等级",
        name: "province",
        names: ["province", "city", "area"],
        type: "vjAddr",
        config: {options: CITY_DATA}
    },
    {label: "模块选择", name: "formality", type: "vjSelect", cmp: "radio", config: genFormOptions(["链接", "文本"], 1)},
    {label: "链接", name: "policyurl", type: "vjInput", show: ["formality", "1"]},
    {label: "文本", name: "policytext", type: "vjInput", config: {type: "textarea", rows: 3}, show: ["formality", "2"]},
];
export const CAPITAL_FM: FormConfig = [
    {label: "标题", name: "title", type: "vjInput"},
    {label: "发布者", name: "createBy", type: "vjInput"},
    {
        label: "投资区间",
        name: "maxinvest",
        names: ["mininvest", "maxinvest"],
        type: "vjNumber",
        cmp: "range",
        inline: ["", "单位(万)"]
    },
    ...addressCfgFn("capaddress"),
    {label: "标签", name: "tag", type: "vjInput", underSuffix: "标签用，隔开"},
    {label: "封面图片", name: "picture", type: "vjUpload"},
    {label: "模块选择", name: "module", type: "vjSelect", config: genFormOptions(["风险投资", "银行融资"], 1)},
    {label: "详情", name: "details", type: "vjInput", cmp: "rich"},
];
export const USER_FM: FormConfig = [
    {label: "手机号", name: "phone", type: "vjInput"},
    {label: "姓名", name: "realname", type: "vjInput"},
    ...addressCfgFn(),
    {label: "角色", name: "role", type: "vjSelect", config: genFormOptions([])},
];
export const TEACHER_CATEGORY_FM: FormConfig = [
    {label: "分类名称", name: "name", type: "vjInput"},
    {label: "状态", name: "status", type: "vjSelect", config: genFormOptions(["上架", "下架"])},
];
export const NEWS_FM: FormConfig = [
    {label: "新闻标题", name: "title", type: "vjInput"},
    {label: "新闻副标题", name: "subtitle", type: "vjInput"},
    {label: "新闻主图", name: "img", type: "vjUpload"},
    {label: "详情", name: "details", type: "vjInput", cmp: "rich"},
];
export const BANNER_FM: FormConfig = [
    {label: "图片链接", name: "name", type: "vjInput"},
    {label: "所属模块", name: "type", type: "vjSelect", config: genFormOptions(["首页", "赛事培训"], -1)},
    {label: "排序", name: "sorting", type: "vjNumber"},
    {label: "选择图片", name: "url", type: "vjUpload"},
];
export const MEMBER_FM: FormConfig = [
    {label: "头像", name: "avatar", type: "vjUpload"},
    {label: "姓名", name: "name", type: "vjInput"},
    {label: "公司", name: "companyName", type: "vjInput"},
    {label: "职位", name: "profession", type: "vjInput"},
    {label: "手机号", name: "phone", type: "vjInput"},
    {label: "邮箱", name: "email", type: "vjInput"},
    {
        label: "省市区",
        name: "provinceCode",
        names: ["provinceCode", "cityCode", "areaCode"],
        type: "vjAddr",
        config: {options: CITY_DATA}
    },
    {label: "入驻孵化器", name: "incubator", type: "vjInput"},
    {label: "高校创业学院", name: "college", type: "vjInput"},
    {label: "个人简介", name: "profile", type: "vjInput"},
    {
        label: "创业阶段",
        name: "entrepreneur",
        type: "vjSelect",
        config: genFormOptions(["暂无", "种子", "天使", "Pre-A", "A轮", "A轮以上6尚未融资"])
    },
];
export const MERCHANT_FM: FormConfig = [
    {label: "封面", name: "picture", type: "vjUpload"},
    {label: "名称", name: "name", type: "vjInput"},
    {label: "联系方式", name: "phone", type: "vjInput"},
    ...addressCfgFn(),
    {label: "产业范围", name: "cyrange", type: "vjInput"},
    {label: "详情", name: "details", type: "vjInput", cmp: "rich"},
];
function addressCfgFn(detailKey?): any {
    return [{
        label: "省市区",
        name: "province",
        names: ["province", "city", "area"],
        type: "vjAddr",
        config: {options: CITY_DATA}
    }, ...(detailKey ? [{label: "详细地址", name: detailKey, type: "vjInput"}] : [])]
}
export function disableFMAll(arr, noCheck, ...keys) {
    return arr.map((item) => ({...item, config: {...item.config, disabled: !keys.includes(item.name)}, noCheck}))
}